<%@ page contentType="text/html; charset=UTF-8" language="java" pageEncoding="UTF-8"%>
<%@include file="/common/taglibs.jsp" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title>WPF</title>
    <link  href="${ctx}/static/css/index.css" rel="stylesheet" type="text/css" /> 
    <link  href="${ctx}/static/ligerui/lib/ligerUI/skins/Aqua/css/ligerui-all.css" rel="stylesheet" type="text/css" /> 
    
    <script src="${ctx }/static/ligerui/lib/jquery/jquery-1.5.2.min.js" type="text/javascript"></script>   
    <script src="${ctx}/static/ligerui/lib/ligerUI/js/ligerui.all.js" type="text/javascript"></script> 

    <link href="${ctx}/static/ligerui/lib/css/common.css" rel="stylesheet" type="text/css" />  
    <link href="${ctx}/static/ligerui/lib/css/index.css" rel="stylesheet" type="text/css" />
    <link href="${ctx}/static/css/instruction/css/main.css" rel="stylesheet" type="text/css" />

    <script src="${ctx }/static/ligerui/lib/ligerUI/js/plugins/ligerForm.js" type="text/javascript"></script>

    <script src="${ctx }/static/ligerui/lib/ligerUI/js/plugins/ligerTip.js" type="text/javascript"></script>
    <script src="${ctx }/static/ligerui/lib/jquery-validation/jquery.validate.min.js" type="text/javascript"></script> 
    <script src="${ctx }/static/ligerui/lib/jquery-validation/jquery.metadata.js" type="text/javascript"></script>

	<script src="${ctx }/static/ligerui/lib/ligerUI/js/plugins/ligerMessageBox.js" type="text/javascript"></script>
	<script src="${ctx }/static/ligerui/lib/json2.js" type="text/javascript"></script>

	<script src="${ctx}/static/ligerui/lib/js/ligerui.expand.js" type="text/javascript"></script> 
	<script src="${ctx }/static/js/jquery.form.js" type="text/javascript"></script>
    <script src="${ctx}/static/ligerui/lib/js/LG.js" type="text/javascript"></script>
    <script src="${ctx}/static/js/common.js" type="text/javascript"></script>
    <script src="${ctx}/static/js/comet/comet.js" type="text/javascript"></script>
    
    <script type="text/javascript">
    	var dialogStu;
        var mainform;
        
        $(document).ready(function ()
        {
            $("#mainbody").ligerLayout({ height: '100%', heightDiff: -3});
            //预加载dialog的背景图片
            LG.prevDialogImage("${ctx}");

            $("#pageloading").hide();
            
            
            mainform=$("#mainform");
            mainform.ligerForm();
            
            loadMembers();
            OnConnect();
            
            //
            $("#messageInput").focus();
        });
        
        //连接虚机
		function OnConnect() {
			window.ViewerX.Disconnect();
			window.ViewerX.HostIP = $("#ip").val();
			window.ViewerX.Port = $("#port").val();
			window.ViewerX.Password=$("#pwd").val();
			window.ViewerX.RemoteInputEnabled="1";
			window.ViewerX.Connect();
		}
		
        //加载讨论组成员
        function loadMembers(){
        	$("#memberList").empty();
        	LG.ajax({
        		url:"${ctx}/qso/instruct/getMembers",
        		data:{groupId:$("#groupId").val()},
        		success:function(result){
        			if(result.success){
        				var items=result.items;
        				for ( var i = 0; i < items.length; i++) {
        					if(items[i].lineStatus == 1){
        						$("#memberList").append(
            							"<li id='li_"+items[i].userId+"' class='onLine'>" + items[i].userName+"</li>");
        					}else{
        						$("#memberList").append(
            							"<li id='li_"+items[i].userId+"' class='offLine'>" + items[i].userName+"</li>");
        					}
        					
        				}
        			}

        		}
        	});
        }
        
    	//群聊,发送消息
    	function send(command) {
    		var message = $("#messageInput").val();
    		if($.trim(message)==""){
    			LG.tip("请输入信息...");
    			return;
    		}
    		doSend(command,message);
    		$("#messageInput").val("");
    	}
    	
    	function doSend(command,message){
    		$.ajax({
    			type : "POST",
    			url : "${ctx}/qso/instruct/sendToGroup",
    			dataType : "json",
    			data : {
    				groupId :$("#groupId").val(),
    				command :command,
    				message : message
    			},
    			success : function(result) {
    			}
    		});
    	}
   

    	//接收服务器消息
    	function receive(result) {
    		if(result.command==comet_command_message){
    			$("#messageArea").append("<BR>\n<font color=blue>" + result.sender + " " + result.sendTime+ " 说: </font>" + result.text+"\n<BR>");
    	        var scrollTop = $("#messageArea")[0].scrollHeight;  
    		    $("#messageArea").scrollTop(scrollTop);
    		}else if(result.command==comet_command_login){//有用户登陆
    			var li=$("#li_"+result.sender);
    			li.removeClass().addClass("onLine");
    		}else if(result.command==comet_command_logout){//有用户登出
    			var li=$("#li_"+result.sender);
    			li.removeClass().addClass("offLine");
    		}else if(result.command==comet_command_notify){
    			alert("讨论组通知: "+result.text);
    		}else if(result.command==comet_command_updateUserList){//更新用户列表
    			loadMembers();
    		}else if(result.command==comet_command_toExit){
                $.ligerDialog.confirm('老师请你退出讨论组!',"toExitG", function (yes) {
                    if (yes){
                    	window.parent.closeTheDialog(6);
                    }
                });
    		}
    	}
    	
    	function selectStu(){
    		$("#ViewerX").hide();
    		dialogStu=$.ligerDialog.open({url: '${ctx}/qso/instruct/toSelectStu/'+$("#groupId").val(),height:550,width:850, isHidden:false, showMax: true, showToggle: true, showMin: true, isResize: true, modal: true, title:"选择学生", onBeforeClose:
    			function() {
    				$("#ViewerX").show();
	  				dialogStu.close(); 
    			}
    		});
    	}
    	
    	function selectStuBack(){
    		loadMembers();
    	}
    	
    	function upload(){
    		if($("#file").val()==""){
    			return;
    		}
    		
            LG.submitForm(mainform, function (result) {
            	if(typeof(result)=="string"){
            		if(result.toLowerCase().indexOf("<pre>")>-1){
            			result = jQuery.parseJSON(jQuery(result).text());
            		}else{
            			result=eval("("+result+")");
            		}
            	}
                if (!result.success) {
                    LG.showError('错误:' + result.message);
                }else {
                	$("#file").val("");
                	loadAttachment();
                }
            });
    	}
    	
    	
    	function loadAttachment(){
        	$("#attachmentList").empty();
        	LG.ajax({
        		url:"${ctx}/qso/attachment/getAttachment",
        		data:{bId:$("#groupId").val(),bType:"qso_discussion_group"},
        		success:function(result){
        			if(result.success){
        				var items=result.items;
        				for(var i=0;i<items.length;i++){
    						$("#attachmentList").append("<li>" + items[i].originalName+ "<a href='${ctx}/qso/attachment/downLoad/"+items[i].id+"'>下载</a></li>");
        				}

        			}else{
        				alert("上传失败!");
        			}

        		}
        	});
    	}
    	
    	function keepCall(){
	    	//每1秒钟（之前为每5分钟）,广播一次消息保持连接(ie下连接会关闭,firefox不会)
    		setInterval(function(){
    			doSend("keepCall","keepCall");
    		}, 1000);
    	}
    	addLoadEvent(keepCall);	
    </script>
</head>
<body style="text-align:center; background:url('${ctx}/static/ligerui/lib/images/qso/bg-1477x768.jpg'); overflow:hidden;">

	<input type="hidden" id="ip" value="${vu.vm.ip }"/>
	<input type="hidden" id="port" value="${vu.vm.port}"/>
	<input type="hidden" id="pwd" value="${vu.vm.pwd}"/>
			
    <div id="pageloading" style="display:block;"></div>
     <div id="mainbody" class="l-mainbody" style="width:99.2%; margin:0 auto; margin-top:3px;" >
     	<!-- <div style="position:absolute; width:60%; height:60%; left:100px; top:100px; color:#000; z-index:10000;">123<iframe id="iftest"></iframe></div> -->
        <div position="center" id="framecenter" style="background:#FFFFFF;"> 
            <div style="width:45%;height:92%; float:left; padding:5px; background:#000;overflow-x:auto;overflow-y:auto"> 
				<OBJECT classid= "CLSID:5220CB21-C88D-11CF-B347-00AA00A28331" VIEWASTEXT>
					<param name="wmode" value="opaque" />
					<PARAM NAME="LPKPath" VALUE="${ctx}/static/vnc/scvncctrl.lpk" />
				</OBJECT>
				<OBJECT id="ViewerX" style="BORDER-RIGHT: 1px solid; BORDER-TOP: 1px solid; BORDER-LEFT: 1px solid; BORDER-BOTTOM: 1px solid; height:99%; width:100%;"
					classid="CLSID:62FA83F7-20EC-4D62-AC86-BAB705EE1CCD" VIEWASTEXT codebase="${ctx}/static/vnc/scvncctrl.cab#version=3,5,4,0">
					<param name="wmode" value="opaque" />
					<PARAM NAME="HostIP" VALUE="">
					<PARAM NAME="Port" VALUE="">
					<PARAM NAME="Password" VALUE="">
					<PARAM NAME="CustomCompression" VALUE="0">
					<PARAM NAME="CustomCompressionLevel" VALUE="6">
					<PARAM NAME="JPEGCompression" VALUE="1">
					<PARAM NAME="JPEGCompressionLevel" VALUE="6">
					<PARAM NAME="CopyRect" VALUE="1">
					<PARAM NAME="EmulateThreeButton" VALUE="1">
					<PARAM NAME="SwapMouseButtons" VALUE="0">
					<PARAM NAME="Encoding" VALUE="7">
					<PARAM NAME="ViewOnly" VALUE="0">
					<PARAM NAME="RestrictPixel" VALUE="0">
					<PARAM NAME="ScaleNum" VALUE="1">
					<PARAM NAME="ScaleDen" VALUE="1">
					<PARAM NAME="ScaleEnable" VALUE="0">
					<PARAM NAME="FullScreen" VALUE="0">
					<PARAM NAME="LocalCursor" VALUE="0">
					<PARAM NAME="MessageBoxes" VALUE="1">
					<PARAM NAME="DisableClipboard" VALUE="1">
					<PARAM NAME="ThumbnailMode" VALUE="0">
					<PARAM NAME="LoginType" VALUE="0">
					<PARAM NAME="MsUser" VALUE="">
					<PARAM NAME="MsDomain" VALUE="">
					<PARAM NAME="MsPassword" VALUE="">
					<PARAM NAME="ProxyIP" VALUE="">
					<PARAM NAME="ProxyPort" VALUE="-1">
					<PARAM NAME="ProxyUser" VALUE="">
					<PARAM NAME="ProxyPassword" VALUE="">
					<PARAM NAME="ProxyType" VALUE="0">
					<PARAM NAME="ConnectionBar" VALUE="1">
					<PARAM NAME="StretchMode" VALUE="0">
					<param name="RemoteInputEnabled" value="1">
				</OBJECT>
               <%--  <img src="${ctx}/static/css/instruction/img/tempWindow.png" style="width:100%;height:100%;" /> --%>
            </div>
            <div style="width:54%; height:95%; float:right;">
            	<div class="inst-winchat">
            		<textarea id="messageArea" style="width:100%;height:100%;background:#D7E7F7;text-align:left;">
            		</textarea>
            	</div>
            	<div class="inst-stu-list">
            		<ul style="margin-left:10px; margin-top:10px;" id="memberList">
            		</ul>
            		<div style="position:absolute;bottom:5px;right:20px;cursor:pointer"><span style="font-size:14px;"  onclick="selectStu()"><img src="${ctx}/static/css/instruction/img/checked_icon.png" style="vertical-align:middle;"/> 选择学生</span></div>
            	</div>
            	<div style="clear:both;"></div>
            	<div class="inst-chat-input">
            		<textarea id="messageInput" style="width:100%;height:70%;color:#555;"></textarea>
            		<div class="inst-chat-send">
            			<div style="width:60px" class="button button2"  onclick="send('message')">
						<div class="button-l"> </div>
						<div class="button-r"> </div> 
						<div class="button-icon"><img src="${ctx}/static/css/instruction/img/sending.png" style="vertical-align:middle;" /> </div>
						<span>发送</span>
						</div>
            		</div>
            	</div>
            	<div class="inst-attachment">
            		<div style="background:#94BDE9; padding:10px;">附件列表</div>
            		<ul class="inst-attachment-list" id="attachmentList">
            		</ul>
            		<div class="inst-attachment-upload">
            		<form name="mainform" method="post"  id="mainform" action="${ctx }/qso/instruct/upload" enctype=”multipart/form-data”>
            			<input type="hidden" id="groupId" name="groupId" value="${groupId }"/>	
            			<input type="file" name="file" id="file" style="width:180px"></input>
            		</form>
            		</div>	
            		<div class="inst-attachment-submit">
            		<div>
            			<div style="width:40px" class="button button2"  onclick="upload()">
						<div class="button-l"> </div>
						<div class="button-r"> </div> 
						<span style="margin:0;">上传</span>
						</div>
            		</div>
            			<!-- <img onclick="upload()" src="${ctx}/static/css/instruction/img/up_arrow.png" style="vertical-align:middle;cursor:pointer;float:right;" /> -->

					</div>
            	</div>
            </div>
            <div style="clear:both;"></div>
            <div style="width:100%; margin-left:10px;"><img src="${ctx}/static/css/instruction/img/avatar.png" style="vertical-align:center;"/> ${vu.user.userNameC }的桌面</div>          
        </div> 
    </div>
    <div class="l-hidden"></div>
</body>
</html>